// pages/studycentre/studycentre.js
const app = getApp();
const DB = wx.cloud.database()
var that;
var util = require('../../utils/util');


Page({
  data: {
    list:[]
  },
  zan(e) {
    console.log(e.currentTarget.id)
    var id = e.currentTarget.id;
    var idx = e.currentTarget.dataset.idx;
    var redu = e.currentTarget.dataset.redu||0;
    console.log('idx',idx)
    redu = redu+1
    wx.cloud.callFunction({
      name: "zan",
      data: {
        id,
        redu
      },
      success(res) {
        wx.showToast({
          title: '赞',
          icon:'none'
        })
        console.log('zan-------res', res)
        that.getdata()
      },
    })

  },
  nozan(e) {
    console.log(e.currentTarget.id)
    var id = e.currentTarget.id;
    var idx = e.currentTarget.dataset.idx;
    var redu = e.currentTarget.dataset.redu || 0;
    console.log('idx', idx)
    redu = redu - 1
    wx.cloud.callFunction({
      name: "zan",
      data: {
        id,
        redu
      },
      success(res) {
        wx.showToast({
          title: '踩',
          icon: 'none'
        })
        console.log('zan-------res', res)
        that.getdata()
      },
    })
  },
  getdata(){

    DB.collection('square').get().then(ress => {
      console.log('ressressressressressressressress', ress.data)

      this.setData({
        list: ress.data.reverse()
      })
    })
  },
  onShow: function () {
    that=this;
   this.getdata()
  },
})
